$(document).ready(function () {
    getRanking()
});
let relate_id =17;
function getRanking() {
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/ranking',
        http_type: 'POST',
        datas: {
            "relate_id": relate_id, //国家ID
            "keyset": "ct_home" //固定值
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            let response = {
                "code": 1,
                "msg": "获取成功",
                "time": "1720622255",
                "data": [
                    {
                        "id": 4,
                        "name": "行业市值排行",
                        "type": 1,
                        "list": [
                            {
                                "id": 1,
                                "name": "汇川技术",
                                "type": "自动化",
                                "amount": 1500,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 95.23
                            },
                            {
                                "id": 2,
                                "name": "柏楚",
                                "type": "自动化",
                                "amount": 1450,
                                "status": 3,
                                "ranking_id": 4,
                                "percent": 92.06
                            },
                            {
                                "id": 3,
                                "name": "正泰",
                                "type": "配电",
                                "amount": 1350,
                                "status": 1,
                                "ranking_id": 4,
                                "percent": 85.71
                            },
                            {
                                "id": 4,
                                "name": "固高",
                                "type": "自动化",
                                "amount": 1250,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 79.36
                            }
                        ]
                    },
                    {
                        "id": 5,
                        "name": "市值增幅Top20",
                        "type": 3,
                        "list": [
                            {
                                "id": 1,
                                "name": "新诺威",
                                "value": "429",
                                "amount": 339,
                                "ranking_id": 5,
                                "percent": 95.23
                            },
                            {
                                "id": 2,
                                "name": "中际旭创",
                                "value": "906",
                                "amount": 319,
                                "ranking_id": 5,
                                "percent": 89.61
                            }
                        ]
                    },
                    {
                        "id": 4,
                        "name": "行业市值排行",
                        "type": 1,
                        "list": [
                            {
                                "id": 1,
                                "name": "汇川技术",
                                "type": "自动化",
                                "amount": 1500,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 95.23
                            },
                            {
                                "id": 2,
                                "name": "柏楚",
                                "type": "自动化",
                                "amount": 1450,
                                "status": 3,
                                "ranking_id": 4,
                                "percent": 92.06
                            },
                            {
                                "id": 3,
                                "name": "正泰",
                                "type": "配电",
                                "amount": 1350,
                                "status": 1,
                                "ranking_id": 4,
                                "percent": 85.71
                            },
                            {
                                "id": 4,
                                "name": "固高",
                                "type": "自动化",
                                "amount": 1250,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 79.36
                            }
                        ]
                    },
                    {
                        "id": 4,
                        "name": "行业市值排行",
                        "type": 1,
                        "list": [
                            {
                                "id": 1,
                                "name": "汇川技术",
                                "type": "自动化",
                                "amount": 1500,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 95.23
                            },
                            {
                                "id": 2,
                                "name": "柏楚",
                                "type": "自动化",
                                "amount": 1450,
                                "status": 3,
                                "ranking_id": 4,
                                "percent": 92.06
                            },
                            {
                                "id": 3,
                                "name": "正泰",
                                "type": "配电",
                                "amount": 1350,
                                "status": 1,
                                "ranking_id": 4,
                                "percent": 85.71
                            },
                            {
                                "id": 4,
                                "name": "固高",
                                "type": "自动化",
                                "amount": 1250,
                                "status": 2,
                                "ranking_id": 4,
                                "percent": 79.36
                            }
                        ]
                    },
                ]
            };
            let resultArray = splitArray(response.data,2);
            for (let i = 0; i < resultArray.length; i++) {
                let swiper_slide = $("<div class='swiper-slide'></div>")
                let swiper_item = $("<div class='swiper_item'></div>")
                let swiper_item_div = $("<div style='display: flex;flex-direction: row;justify-content: space-between;'></div>")
                for (let j = 0; j < resultArray[i].length; j++) {
                    let content_box_bottom_center_box = $("<div class='content_box_bottom_center_box'></div>")
                    let span_1 = $("<span></span>")
                    $(span_1).text(resultArray[i][j].name)
                    let span_2 = $("<span></span>")
                    $(span_2).text("查看完整排名")
                    let div_1 = $("<div class='ss'></div>")
                    let div_2 = $("<div class='ssss'></div>")
                    let ranking_table = $("<table class='ranking_table'></table>")
                    let tr_th = $("<tr></tr>")
                    let tr_th_1 = $("<th class='cell_bg'></th>")
                    $(tr_th_1).text('序号')
                    let tr_th_2 = $("<th class='cell_bg'></th>")
                    $(tr_th_2).text('企业')
                    let tr_th_3 = $("<th class='cell_bg'></th>")
                    $(tr_th_3).text('类型')
                    let tr_th_4 = $("<th class='cell_bg'></th>")
                    $(tr_th_4).text('市值')
                    $(tr_th).append(tr_th_1)
                    $(tr_th).append(tr_th_2)
                    $(tr_th).append(tr_th_3)
                    $(tr_th).append(tr_th_4)
                    $(ranking_table).append(tr_th)
                    for (let k = 0; k < resultArray[i][j].list.length; k++) {
                        let tr = $("<tr></tr>")
                        let td_1 = $("<td></td>")
                        $(td_1).text(resultArray[i][j].list[k].id)
                        let td_2 = $("<td></td>")
                        $(td_2).text(resultArray[i][j].list[k].name)
                        let td_3 = $("<td></td>")
                        $(td_3).text(resultArray[i][j].list[k].type)
                        let td_4 = $("<td class='market_value'></td>")
                        let td_4_div = $("<div></div>")
                        let td_4_span = $("<span></span>")
                        $(td_4_span).text(resultArray[i][j].list[k].percent)
                        $(td_4).append(td_4_div)
                        $(td_4).append(td_4_span)
                        $(tr).append(td_1)
                        $(tr).append(td_2)
                        $(tr).append(td_3)
                        $(tr).append(td_4)
                        $(ranking_table).append(tr)
                    }
                    $(div_2).append(ranking_table)
                    $(div_1).append(div_2)
                    $(content_box_bottom_center_box).append(span_1)
                    $(content_box_bottom_center_box).append(span_2)
                    $(content_box_bottom_center_box).append(div_1)
                    $(swiper_item_div).append(content_box_bottom_center_box)
                }
                $(swiper_slide).append(swiper_item_div)
                $(".swiper-wrapper").append(swiper_slide)
            }
            var myRankingSwiper = new Swiper(".swiper-ranking-container", {
                direction: "horizontal",
                loop: false,
                pagination: ".swiper-pagination",
                paginationElement: "li",
                uniqueNavElements: false,
                navigation: {
                    nextEl: ".my-swiper-button-next",
                    prevEl: ".my-swiper-button-prev",
                },
            });
            $(document).on('click', '.my-swiper-button-next', function() {
                myRankingSwiper.slideNext();
            });

            $(document).on('click', '.my-swiper-button-prev', function() {
                myRankingSwiper.slidePrev();
            });

        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}
function splitArray(array, size) {
    var result = [];
    for (var i = 0; i < array.length; i += size) {
        result.push(array.slice(i, i + size));
    }
    return result;
}

$("#national_table").click((e)=>{
    // 设置当前模块国家的ID
    // localStorage.setItem("brand_category_id",e.target.dataset.id || '130')
    relate_id = e.target.dataset.id;
    $('.nav_com').html(appendHtml(e.target.innerText));
    getRanking();
    console.log('当前点击的对象id===>>>',e.target.innerText);
    console.log('当前点击的对象innerText===>>>',e.target.innerText);
})
 